package 潜水员;

import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static int N = 30, M = 90;
    static int[][] f = new int[N][M];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();//O2
        int m = in.nextInt();//N2
        int k = in.nextInt();//数量
        for (int i = 0; i <= n; i++) {
            Arrays.fill(f[i], 0x3f3f3f3f);
        }
        f[0][0] = 0;
        while (k-- > 0) {
            int v1 = in.nextInt();
            int v2 = in.nextInt();
            int w = in.nextInt();
            for (int i = n; i >= 0; i--) {
                for (int j = m; j >= 0; j--) {
                    f[i][j] = Math.min(f[i][j], f[Math.max(0, i - v1)][Math.max(0, j - v2)] + w);
                }
            }
        }
        System.out.println(f[n][m]);
    }
}
